/***************************************************************************
 创建者：          hualei
 开始时间：      2018.12.20
 copyright:(C)    深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   ROBOT_MOVE 机械手控制指令属性编辑类
 *
 ***************************************************************************/
#include "../RobotMoveInstructionView/robotmoveinstructionview.h"
#include "robotmoveinstructiondelegate.h"
#include <QDebug>

RobotMoveInstructionDelegate::RobotMoveInstructionDelegate(QWidget *parent)
    : QWidget(parent)
{
}

void RobotMoveInstructionDelegate::initView()
{
    robotMoveInstructionView->noteStr = "";
    robotMoveInstructionView->instructionStr = "";
    robotMoveInstructionView->sendParameterStr = "";
    robotMoveInstructionView->waitParameterStr = "";
    robotMoveInstructionView->jmpLableValue = 1;
    robotMoveInstructionView->timeOutValue = 5;
    robotMoveInstructionView->localIP = "127.0.0.1";
    robotMoveInstructionView->serverIP = "";
    robotMoveInstructionView->communicationPort = 0;
    robotMoveInstructionView->robotMoveBusType = EM_ROBOT_MOVE_BUS_CLIENT;
}

void RobotMoveInstructionDelegate::instructionEditFinished_Slot()
{
    // 指令格式: ROBOT_MOVE [sendParameter],[waitParameter],TIMEOUT 1,JMP LBL[1]  //

    robotMoveInstructionView->instructionStr = tr("ROBOT_MOVE ");
    QString tmpIP;
    QString tmpBusType;
    if(robotMoveInstructionView->robotMoveBusType == EM_ROBOT_MOVE_BUS_CLIENT)
    {
        tmpIP = robotMoveInstructionView->serverIP;
        tmpBusType = tr("CLIENT");
    }
    else if(robotMoveInstructionView->robotMoveBusType == EM_ROBOT_MOVE_BUS_SERVER)
    {
        tmpIP = robotMoveInstructionView->localIP;
        tmpBusType = tr("SERVER");
    }
    robotMoveInstructionView->instructionStr += tr("IP[") + tmpIP + tr("],");
    robotMoveInstructionView->instructionStr += tr("PORT[") + QString::number(robotMoveInstructionView->communicationPort) + tr("],");
    robotMoveInstructionView->instructionStr += tmpBusType;
    robotMoveInstructionView->instructionStr += tr(",SEND[") + robotMoveInstructionView->sendParameterStr + tr("],");
    robotMoveInstructionView->instructionStr += tr("WAIT[") + robotMoveInstructionView->waitParameterStr + tr("],");
    robotMoveInstructionView->instructionStr += tr("TIMEOUT ") + QString::number(robotMoveInstructionView->timeOutValue) + tr(",");
    robotMoveInstructionView->instructionStr += tr("JMP LBL[") + robotMoveInstructionView->jmpLableValue + tr("]  //");
    robotMoveInstructionView->instructionStr += robotMoveInstructionView->noteStr;

    qDebug() << "Edit Finished Instruction :" << robotMoveInstructionView->instructionStr;
}

void RobotMoveInstructionDelegate::cleanNote_Slot()
{
    robotMoveInstructionView->noteStr.clear();
}

